package com.example.user.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.user.utils.demo;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.user.mapper.UserMapper;
import com.example.user.entity.User;
import com.example.user.service.UserService;
/**
 * @author: mtl
 * @Date: 2022/1/18 18:00
 * @Description: 
 */
@Service("UserService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Resource
    UserMapper userMapper;


    public static Integer size = 1;


    public final TimeInterval timer = new TimeInterval();

    @Override
    public Set<String> byUserRoles(String username) {
        return userMapper.byUserPermissions(username);
    }

    @Override
    public Set<String> byUserPermissions(String username) {
        return userMapper.byUserPermissions(username);
    }

    @Async
    @Override
    public String batchList(Integer size, Integer page) {
        for (int i = 0; i < page; i++) {
            timer.interval();
            size++;
            List<User> userList = demo.getUserList(size);
            boolean b = saveBatch(userList);
            System.out.println(size+"次数:"+b);
            Console.log("Timer {} ms", timer.intervalRestart());
        }
        return Convert.toStr(size);
    }
}
